<html>
<head><meta charset="utf-8"><title>simplify_comparision_integral overwriting locals · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral.20overwriting.20locals.html">simplify_comparision_integral overwriting locals</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212278083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral%20overwriting%20locals/near/212278083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral.20overwriting.20locals.html#212278083">(Oct 05 2020 at 09:51)</a>:</h4>
<p>Is there something preventing us from creating mir like this?</p>
<div class="codehilite"><pre><span></span><code>        StorageLive(_2);                 // scope 0 at ./example.rs:3:9: 3:10
        _2 = Eq(_1, const 3_i32);   // scope 0 at ./example.rs:3:13: 3:21
        StorageLive(_4);                 // scope 1 at ./example.rs:4:9: 4:10
        _4 = &amp;mut _1;                    // scope 1 at ./example.rs:4:13: 4:21
        (*_4) = const 4_i32;             // scope 2 at ./example.rs:5:5: 5:11
        StorageLive(_5);                 // scope 2 at ./example.rs:6:8: 6:9
        _5 = _2;                         // scope 2 at ./example.rs:6:8: 6:9
        switchInt(_5) -&gt; [false: bb1, otherwise: bb2];
</code></pre></div>



<a name="212278168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral%20overwriting%20locals/near/212278168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral.20overwriting.20locals.html#212278168">(Oct 05 2020 at 09:52)</a>:</h4>
<p>using a local by copy and then taking a mutable reference to that local</p>



<a name="212278181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral%20overwriting%20locals/near/212278181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral.20overwriting.20locals.html#212278181">(Oct 05 2020 at 09:52)</a>:</h4>
<p>I am kind of afraid that we misoptimize something like this <a href="https://rust.godbolt.org/z/865eW4">https://rust.godbolt.org/z/865eW4</a></p>



<a name="212278217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral%20overwriting%20locals/near/212278217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral.20overwriting.20locals.html#212278217">(Oct 05 2020 at 09:53)</a>:</h4>
<p>but we first insert</p>
<div class="codehilite"><pre><span></span><code>_2 = _1
_4 = Eq(move _2, const 3_i32);
</code></pre></div>



<a name="212278299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral%20overwriting%20locals/near/212278299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral.20overwriting.20locals.html#212278299">(Oct 05 2020 at 09:54)</a>:</h4>
<p>so this seems like it might be an non issue, even if I would feel safer if we only apply <code>SimplyfyComparisionIntegral</code> if the op is a move (or we explicitly check if that local is leaked after the comparision)</p>



<a name="212278515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral%20overwriting%20locals/near/212278515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/simplify_comparision_integral.20overwriting.20locals.html#212278515">(Oct 05 2020 at 09:57)</a>:</h4>
<p>(recently had this misoptimization in my own compiler <a href="https://github.com/lcnr/computer/blob/2e75238dd3f10ca8d856aadfa3677007a4575b5a/boulder/lir/src/optimize/simplify_comparision_branch.rs#L24">https://github.com/lcnr/computer/blob/2e75238dd3f10ca8d856aadfa3677007a4575b5a/boulder/lir/src/optimize/simplify_comparision_branch.rs#L24</a>)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>